/*-
 *******************************************************************************
 * Copyright (c) 2011, 2016 Diamond Light Source Ltd.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Matthew Gerring - initial API and implementation and/or initial documentation
 *******************************************************************************/
package org.eclipse.scanning.api.ui.auto;

import org.eclipse.scanning.api.IModelProvider;

/**
 *
 * Create a model editor which is autogenerated user interface for
 * editing models.
 *
 * This viewer will normally be castable to org.eclipse.jface.viewers.ISelectionProvider
 * in order to add selection listeners.
 *
 * @author Matthew Gerring
 * @param T the type of the bean for which this is a viewer.
 */
public interface IModelViewer<T> extends IModelProvider<T>{

	/**
	 * Called to create the part control.
	 * The type U is usually Composite but may be parameterised for non-SWT
	 *
	 *
	 * @param ancestor
	 * @return
	 */
	<U> U createPartControl(U ancestor);


	/**
	 * The model which we are editing
	 * @param model
	 * @throws exception if interface cannot be rendered from this model.
	 */
	@Override
	void setModel(T model) throws Exception;


	/**
	 * The model which we are editing
	 * @param model
	 */
	@Override
	T getModel();

    /**
     * Call to dispose
     */
	void dispose();

	/**
	 * Get the underlying Control which the UI system is using.
	 * @return
	 */
	<U> U getControl();

	/**
	 * Refresh the table or UI items
	 */
	void refresh();

	/**
	 * Make the viewer take focus to its main control.
	 */
	void setFocus();

    /**
     * Call to apply the cell editor value in the editing bean.
     */
	void applyEditorValue();

	/**
	 * If this viewer is linked to an e3 part with an IViewSite,
	 * it may be provided here.
	 *
	 * @param site
	 */
	<V> void setViewSite(V site);
}
